/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ItemOrderGUI.java
 *
 * Created on 23-06-2011, 09:05:12
 */
package GUILayer;
import ControlLayer.*;
/**
 *
 * @author Jonas Kristensen
 */
public class ItemOrderGUI extends javax.swing.JFrame {

    private ItemController itemController;
    private ItemOrderGUI2 itemOrderGUI2;
    LoginGUI loginGUI;
    /** Creates new form ItemOrderGUI */
    public ItemOrderGUI(LoginGUI login) {
        initComponents();
        loginGUI = login;
        itemController = new ItemController();
    }
    
    public void itemWhichHaveBeenOrdered()
    {
        boolean itemsOrdered = false;
        for(String barcode : itemController.listOfItems())
        {
            if(itemController.findItemByBarcode(barcode).getOrderedBySupplier() == true)
            {
                itemHaveBeenOrderedTextArea.append("Barcode: " + itemController.findItemByBarcode(barcode).getBarcode());
                itemHaveBeenOrderedTextArea.append(" | Item nb: " + itemController.findItemByBarcode(barcode).getItemNumber());
                itemHaveBeenOrderedTextArea.append(" | Name: " + itemController.findItemByBarcode(barcode).getName());
                itemHaveBeenOrderedTextArea.append(" | Amount in stock: " + itemController.findItemByBarcode(barcode).getAmountInStock());
                itemHaveBeenOrderedTextArea.append(" | Amount pr order: " + itemController.findItemByBarcode(barcode).getAmountPrOrder());
                itemHaveBeenOrderedTextArea.append(" | Minimum stock: " + itemController.findItemByBarcode(barcode).getMinStock());
                itemHaveBeenOrderedTextArea.append(" | Maximum stock: " + itemController.findItemByBarcode(barcode).getMaxStock());
                itemHaveBeenOrderedTextArea.append("\n");
                if(!itemsOrdered)
                {
                    itemsOrdered = true;
                }
                
            }
        }
        if(!itemsOrdered)
        {
             itemHaveBeenOrderedTextArea.append("No items have been ordered");
             itemHaveBeenOrderedTextArea.append("\n");
        }
    }
    
    public void itemWhichHaveToBeOrdered()
    {
        if(!itemController.itemsToOrderBySupplier().isEmpty())
        {
            for(String barcode : itemController.itemsToOrderBySupplier())
            {
                itemWhichHaveToBeOrdered.append("Barcode: " + itemController.findItemByBarcode(barcode).getBarcode());
                itemWhichHaveToBeOrdered.append(" | Item nb: " + itemController.findItemByBarcode(barcode).getItemNumber());
                itemWhichHaveToBeOrdered.append(" | Name: " + itemController.findItemByBarcode(barcode).getName());
                itemWhichHaveToBeOrdered.append(" | Amount in stock: " + itemController.findItemByBarcode(barcode).getAmountInStock());                    
                itemWhichHaveToBeOrdered.append(" | Amount pr order: " + itemController.findItemByBarcode(barcode).getAmountPrOrder());
                itemWhichHaveToBeOrdered.append(" | Minimum stock: " + itemController.findItemByBarcode(barcode).getMinStock());
                itemWhichHaveToBeOrdered.append(" | Maximum stock: " + itemController.findItemByBarcode(barcode).getMaxStock());
                itemWhichHaveToBeOrdered.append("\n"); 
            }
        }
        else
        {
            itemWhichHaveToBeOrdered.append("No items have to be ordered");    
        }
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        itemOrderPanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        itemHaveBeenOrderedTextArea = new javax.swing.JTextArea();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        itemWhichHaveToBeOrdered = new javax.swing.JTextArea();
        cancelButton = new javax.swing.JButton();
        orderItemButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        itemOrderPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Items which have been ordered"));

        itemHaveBeenOrderedTextArea.setColumns(20);
        itemHaveBeenOrderedTextArea.setEditable(false);
        itemHaveBeenOrderedTextArea.setRows(5);
        jScrollPane1.setViewportView(itemHaveBeenOrderedTextArea);

        javax.swing.GroupLayout itemOrderPanelLayout = new javax.swing.GroupLayout(itemOrderPanel);
        itemOrderPanel.setLayout(itemOrderPanelLayout);
        itemOrderPanelLayout.setHorizontalGroup(
            itemOrderPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(itemOrderPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 950, Short.MAX_VALUE)
                .addContainerGap())
        );
        itemOrderPanelLayout.setVerticalGroup(
            itemOrderPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(itemOrderPanelLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Items which have to be ordered"));

        itemWhichHaveToBeOrdered.setColumns(20);
        itemWhichHaveToBeOrdered.setEditable(false);
        itemWhichHaveToBeOrdered.setRows(5);
        jScrollPane2.setViewportView(itemWhichHaveToBeOrdered);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 950, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 223, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        cancelButton.setText("Cancel");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        orderItemButton.setText("Order items");
        orderItemButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                orderItemButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(itemOrderPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(orderItemButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 828, Short.MAX_VALUE)
                        .addComponent(cancelButton)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(itemOrderPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cancelButton)
                    .addComponent(orderItemButton))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        this.dispose();
    }//GEN-LAST:event_cancelButtonActionPerformed

    private void orderItemButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_orderItemButtonActionPerformed
        if(!itemController.itemsToOrderBySupplier().isEmpty())
        {
        for(String barcode : itemController.itemsToOrderBySupplier())
            {
                String itemBarcode = itemController.findItemByBarcode(barcode).getBarcode();
                itemOrderGUI2 = new ItemOrderGUI2(itemBarcode, this);
                itemOrderGUI2.setBounds(loginGUI.getWidthStartWindow(), loginGUI.getHeightStartWindow(), 250,300);
                itemOrderGUI2.setVisible(true);
            }
        }
    }//GEN-LAST:event_orderItemButtonActionPerformed

    public void clearTextArea1()
    {
        itemWhichHaveToBeOrdered.setText("");
    }
    public void clearTextArea2()
    {
        itemHaveBeenOrderedTextArea.setText("");
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelButton;
    private javax.swing.JTextArea itemHaveBeenOrderedTextArea;
    private javax.swing.JPanel itemOrderPanel;
    private javax.swing.JTextArea itemWhichHaveToBeOrdered;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton orderItemButton;
    // End of variables declaration//GEN-END:variables
}
